﻿//**********************************************************
//Copyright(C)2010 By 波特商网公司 版权所有。
//
//文件名：
//文件功能：用于2级菜单Tab效果显示
//
//创建标识：齐李平 || 2011-04-01
//
//修改标识：
//修改描述：
//**********************************************************

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using Hmc.IM.Common.Properties;

namespace Hmc.IM.Common.UserControls
{
    /// <summary>
    /// Tag按钮
    /// </summary>
    public class ucMenuButton : PictureBox
    {
        //选中状态背景图片（图片）
        private Image _currentBackgroundImage = Resources.menu_current_bg;

        /// <summary>
        /// Tag按钮当前状态图片
        /// </summary>
        public Image CurrentBackgroundImage
        {
            get { return _currentBackgroundImage; }
            set { _currentBackgroundImage = value; }
        }

        //背景图片（默认）
        private Image _backgoundImage = Resources.menu_bg;

        //显示在Tag上的文本
        private Label label = new Label();
        private string _text;

        /// <summary>
        /// 按钮文字
        /// </summary>
        public string TagText
        {
            get
            {
                return _text;
            }
            set
            {
                label.Text = value;
                _text = value;
            }
        }

        /// <summary>
        /// 文本颜色
        /// </summary>
        private Color _textColor = Color.FromArgb(48, 48, 48);

        /// <summary>
        /// 文本颜色
        /// </summary>
        public Color TextColor
        {
            get { return _textColor; }
            set {
                label.ForeColor = value;
                _textColor = value;
            }
        }

        private bool _isChecked;
        /// <summary>
        /// 是否选中
        /// </summary>
        public bool IsChecked
        {
            get { return _isChecked; }
            set { if (value == true)this.BackgroundImage = CurrentBackgroundImage; _isChecked = value; }
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        public ucMenuButton()
        {
            label.AutoSize = false;
            label.BackColor = Color.Transparent;
            label.Dock = DockStyle.Fill;
            label.TextAlign = ContentAlignment.MiddleCenter;
            label.Parent = this;
            //label.ForeColor = TextColor;
            label.Click += new EventHandler(label_Click);
            label.MouseEnter += new EventHandler(label_MouseEnter);
            label.MouseLeave += new EventHandler(label_MouseLeave);
            this.BackgroundImage = _backgoundImage;
        }

        /// <summary>
        /// 重写控件Size
        /// </summary>
        /// <param name="e"></param>
        protected override void OnResize(EventArgs e)
        {
            base.OnResize(e);
            this.Width = 80;
            this.Height = 26;
        }

        /// <summary>
        /// Label鼠标移出事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void label_MouseLeave(object sender, EventArgs e)
        {
            this.OnMouseLeave(e);
        }

        /// <summary>
        /// Label鼠标移入事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void label_MouseEnter(object sender, EventArgs e)
        {
            this.OnMouseEnter(e);
        }

        /// <summary>
        /// Label鼠标点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void label_Click(object sender, EventArgs e)
        {
            this.OnClick(e);
        }

        /// <summary>
        /// 鼠标进入当前区域
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseEnter(EventArgs e)
        {
            base.OnMouseEnter(e);
            if (this.CurrentBackgroundImage != null)
            {
                _backgoundImage = this.BackgroundImage;
                this.BackgroundImage = this.CurrentBackgroundImage;
            }
        }

        /// <summary>
        /// 鼠标离开当前区域
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseLeave(EventArgs e)
        {
            base.OnMouseLeave(e);

            this.BackgroundImage = _backgoundImage;
        }

    }
}
